package com.violet.controller.manager;

import com.violet.domain.dto.manager.MRiderDto;
import com.violet.domain.result.Result;
import com.violet.domain.result.ResultPage;
import com.violet.domain.search.MyPage;
import com.violet.domain.search.manager.MRiderSearch;
import com.violet.domain.vo.manager.MRiderVo;
import com.violet.service.manager.MRiderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manager/rider")
@RequiredArgsConstructor
public class MRiderController {

    private final MRiderService service;

    // 分页搜索
    @GetMapping("/search")
    public ResultPage<List<MRiderVo>> search(@ModelAttribute MRiderSearch search, @ModelAttribute MyPage myPage) {
        return service.search(search, myPage);
    }

    // 获取所有在职的骑手
    @GetMapping
    public Result<List<MRiderVo>> getOnJobAll() {
        return Result.success(service.getOnJobAll(), "获取数据");
    }

    @PostMapping
    public Result<MRiderVo> create(@RequestBody MRiderDto dto) {
        return Result.success(service.create(dto), "创建数据");
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteById(@PathVariable String id) {
        return Result.success(service.deleteById(id), "删除数据");
    }

    @PutMapping("/{id}")
    public Result<MRiderVo> updateById(@PathVariable String id, @RequestBody MRiderDto dto) {
        return Result.success(service.updateById(id, dto), "更新数据");
    }

}
